package com.zjcode.cdcer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chinatechstar.component.commons.entity.MPage;
import com.chinatechstar.component.commons.result.PaginationBuilder;
import com.chinatechstar.component.commons.service.BaseService;
import com.chinatechstar.component.commons.supports.PageData;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zjcode.cdcer.mapper.CerDemoInfoMapper;
import com.zjcode.cdcer.model.CerDemoInfo;
import com.zjcode.cdcer.service.CerDemoInfoService;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName:CerDemoInfoServiceImpl
 * @功能：
 * @author：wlei
 * @日期：2022/7/9-02:23
 **/
@Service
public class CerDemoInfoServiceImpl implements CerDemoInfoService, BaseService {

    @Autowired
    private CerDemoInfoMapper cerDemoInfoMapper;

    @Override
    public List<CerDemoInfo> listAllNoPage() {

        List<CerDemoInfo> list = cerDemoInfoMapper.selectList(new QueryWrapper<CerDemoInfo>());
        return list;
    }

    @Override
    public int insert(CerDemoInfo cerDemoInfo) {
        return cerDemoInfoMapper.insert(cerDemoInfo);
    }

    @Override
    public Map<String, Object> listByPage(PageData pageData) {
        MPage mPage = getPageInfo(pageData);
        Page<Object> page = PageHelper.startPage(mPage.getCurrentPage(), mPage.getPageSize());
        List<LinkedHashMap<String, Object>> list = new ArrayList<>();
        list.addAll(cerDemoInfoMapper.listByPage());
        return PaginationBuilder.buildResult(list,
                                             page.getTotal(),
                                             mPage.getCurrentPage(),
                                             mPage.getPageSize());
    }

    @Override
    public int inserBtList(List<CerDemoInfo> list) {
        return cerDemoInfoMapper.insertList(list);
    }

    @Override
    public List<CerDemoInfo> selectAllDeleteData() {
        List<CerDemoInfo> list = cerDemoInfoMapper.selectAllByDeletedOrderByInsertDatetimeDesc(1);
        return list;
    }

    @Override
    public Map<String, Object> getAllTestData(PageData pageData) {
        MPage mPage = getPageInfo(pageData);
        Page<Object> page = PageHelper.startPage(mPage.getCurrentPage(), mPage.getPageSize());
        List<LinkedHashMap<String, Object>> list = new ArrayList<>();
        list.addAll(cerDemoInfoMapper.getAllTestData());
        return PaginationBuilder.buildResult(list,
                                            page.getTotal(),
                                            mPage.getCurrentPage(),
                                            mPage.getPageSize());
    }
}
